﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace Simple_Subliminal_Messenger
{
    public partial class Form1 : Form
    {
        Queue<string> lines;
        int milisectimer = 200;
        double opacity = 0.12;
        public Form1()
   
        {
            InitializeComponent();
            textBox1.Text = "200";
            lines = new Queue<string>();


            this.toolTip1.SetToolTip(this.opacitybox, "Opacity Values must be between 0 and 1");
        }

  

        private void SpawnButton_Click(object sender, EventArgs e)
        {
            SubliminalDisplay sd = new SubliminalDisplay(lines,milisectimer,opacity);
            sd.Show();
        }

        /// <summary>
        /// browse for file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditButton_Click(object sender, EventArgs e)
        {
               OpenFileDialog openFileDialog1 = new OpenFileDialog();
               string [] stringlines;
      
                DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
                if (result == DialogResult.OK) // Test result.
                {
                    string file = openFileDialog1.FileName;
                    try
                    {
                        stringlines = File.ReadAllLines(file);
                        lines = new Queue<string>(stringlines);

                    }
                    catch (IOException)
                    {
                    }
                }

        }

        private void QuitButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                milisectimer = int.Parse(textBox1.Text);
            }

            catch //NAN
            {
 
            }
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            try
            {   //opacity must be between 0 and 1
                if (double.Parse(textBox1.Text) > 1 || double.Parse(textBox1.Text) < 0)
                { 
                    //do nothing because it's invalid
                }
                else 
                {
                    opacity = double.Parse(textBox1.Text);
                }
           
            }
            catch { }
        }
    }
}
